function renderCheckboxHead(thElem, col) {
    thElem.className = 'et-checkbox-th';

    let checkboxElem = document.createElement('input');
    checkboxElem.type = 'checkbox';
    thElem.appendChild(checkboxElem);

    //点击全选或者全不选
    checkboxElem.onclick = function () {
        let tbodyElem = thElem.parentNode.parentNode.nextElementSibling;
        let checkboxElemArray = tbodyElem.getElementsByTagName('input');
        for (let tbodyCheckboxElem of checkboxElemArray) {
            tbodyCheckboxElem.checked = checkboxElem.checked;
        }
    };
}

function renderCheckboxBody(tdElem, col, rawData) {
    let checkboxElem = document.createElement('input');
    checkboxElem.type = 'checkbox';
    tdElem.appendChild(checkboxElem);
    checkboxElem.onclick = function () {
        let tbodyElem = tdElem.parentNode.parentNode;
        let theadElem = tbodyElem.previousElementSibling;
        //头只有一个checkbox
        let theadCheckboxElem = theadElem.getElementsByTagName('input')[0];
        let checkboxElemArray = tbodyElem.getElementsByTagName('input');
        theadCheckboxElem.checked = true;
        for (let tbodyCheckboxElem of checkboxElemArray) {
            theadCheckboxElem.checked = theadCheckboxElem.checked && tbodyCheckboxElem.checked;
        }
    };
}


export { renderCheckboxHead, renderCheckboxBody };